<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="../vendor/jquery/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="../js/bootstarp-3.3.7/css/bootstrap.min.css" />
		<script src="../js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="../js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="../js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="../assets/layui-v2.4.5/layui/css/layui.css" media="all" />
		<script src="../assets/layui-v2.4.5/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script>
			$(function() { //, headers: { 'x-requested-with': 'XMLHttpRequest' }
				$.ajaxSetup({
					crossDomain: true,
					xhrFields: {
						withCredentials: true
					}
				});
			});
		</script>
		<script type="text/javascript">
			
			var lx = 'yd';
			$(function() {
//				//格式化时间日期
//				var tiem = new Date();
//				//除了数字以外全部都替换为-
//				var ftime = tiem.toLocaleDateString().replace(/[^0-9]/ig, "-");
//				if(tiem.getMonth() + 1 < 10) {
//					ftime = ftime.replace("-", "-0");
//				}
//				if(tiem.getDate() < 10) {
//					ftime = ftime.replace(/[^0]$/, "0" + tiem.getDate());
//				}
				//				$("#time2").val(ftime);
//				$("#time1,#time2").attr("max", ftime);

				layui.use(['element', 'layer', 'table'], function() {
					var element = layui.element,
						layer = layui.layer,
						table = layui.table;
					//进入界面时弹框
					layer.msg('欢迎来到年月报表统计功能模块');
					//监听Tab切换
					element.on('tab(demo)', function(data) {
						if(this.innerHTML.trim() == '月度统计') {
							lx = 'yd';
							$("#time1").val("");
							$("#time2").val("");
						} else {
							lx = 'nd';
							$("#time1").val("");
							$("#time2").val("");
						}
						layer.tips('切换到:' + this.innerHTML, this, {
							tips: 1
						});
					});
					//加载表格
					table.render({
						elem: '#tab1demo',
						height: 312,
						url: 'http://127.0.0.1:8099/Report_StaController/queryAllAndBlur', //数据接口
						page: true, //开启分页
						text: '0',
						id: 'zycx',
						toolbar: 'true',
						cols: [
							[ //表头
								{
									field: 'rq',
									title: '月度',
									fixed: 'left'
								}, {
									field: 'jzrc',
									title: '就诊人次',
									sort: true
								}, {
									field: 'ssje',
									title: '实收金额',
									sort: true
								}, {
									field: 'xjzf',
									title: '现金支付',
									sort: true
								}, {
									field: 'wxzf',
									title: '微信支付',
									sort: true
								}, {
									field: 'zfbzf',
									title: '支付宝支付',
									sort: true
								}, {
									field: 'ghf',
									title: '挂号费',
									sort: true
								}, {
									field: 'cff',
									title: '处方费',
									sort: true
								}
							]
						]
					});

					//加载表格
					table.render({
						elem: '#tab2demo',
						height: 312,
						url: 'http://127.0.0.1:8099/Report_StaController/queryAllAndBlur', //数据接口
						page: true, //开启分页
						text: '0',
						id: 'ndcx',
						toolbar: 'true',
						cols: [
							[ //表头
								{
									field: 'rq',
									title: '月度',
									fixed: 'left'
								}, {
									field: 'jzrc',
									title: '就诊人次',
									sort: true
								}, {
									field: 'ssje',
									title: '实收金额',
									sort: true
								}, {
									field: 'zcje',
									title: '支出金额',
									sort: true
								}, {
									field: 'sznbl',
									title: '所占年度比例',
									sort: true
								}
							]
						]
					});

					$("#butt1").on("click", function() {
						var tiem1 = $("#time1").val();
						var tiem2 = $("#time2").val();
						if(tiem1 > tiem2) {
							$("#time1").val(tiem2);
							$("#time2").val(tiem1);
						}
						if(isNaN(Date.parse(tiem2) / 1000)) {
							$("#time2").val(tiem1);
						}
						var curMonthDays = new Date(new Date($("#time2").val()).getFullYear(), (new Date($("#time2").val()).getMonth()+1), 0).getDate();
						var mhEndTime = '';
						if(!isNaN($("#time2").val()) || $("#time2").val() != ''){
							mhEndTime = Date.parse($("#time2").val()) / 1000 + (curMonthDays*86400);
						}
						if(lx.trim() == 'yd') {
							table.reload('zycx', {
								where: {
									'mhStartTime': Date.parse($("#time1").val()) / 1000,
									'mhEndTime': mhEndTime,
									'lx' : lx
								}
							});
						} else {
							if (tiem1.trim().length>4 && tiem2.trim().length>4 ) {
								if (tiem1.substr(0,4) != tiem2.substr(0,4)) {
									alert("请输入同一年的日期!");
									return;
								}
							}
							table.reload('ndcx', {
								where: {
									'mhStartTime': Date.parse($("#time1").val()) / 1000,
									'mhEndTime': mhEndTime,
									'lx' : lx
								}
							});
							//							}
						}
					})
				});
			})
		</script>
	</head>

	<body>
		<form id="form1" class="form-inline">
			<input type="month" style="width: 200px;" class="form-control" name="StartTime" id="time1" />
			<input type="month" style="width: 200px;" class="form-control" name="EndTime" id="time2" />
			<input type="button"  class="btn btn-default" value="查询" id="butt1" />
		</form>
		<div class="layui-tab layui-tab-brief" lay-filter="demo">
			<ul class="layui-tab-title">
				<li class="layui-this">月度统计</li>
				<li>年度统计</li>
			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
					<table id="tab1demo" lay-filter="test"></table>
					<!--用不着的东西-->
					<!--<script type="text/html" id="toolbarDemo"></script>-->
				</div>
				<div class="layui-tab-item">
					<table id="tab2demo" lay-filter="test"></table>
				</div>
			</div>
		</div>
	</body>

</html>